package com.lz.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;

import com.lz.dao.TheaDAO;
import com.lz.util.ConnMgr;
import com.lz.util.ConstantConfig;
import com.lz.util.SQLConfig;

public class TheaDAO {
	
	protected Connection conn=null;
	
	public TheaDAO(){
		conn=ConnMgr.getConnection();
	}
	
	public void closeConnection(){
		try{
			conn.close();
		}
		catch(SQLException sqlex){
			conn=null;
			sqlex.printStackTrace();
		}
	}
	
	
	
	 public static String getProperty(String key){
	    	ResourceBundle labels =
			    ResourceBundle.getBundle(ConstantConfig.PROP_FILENAME);
	    	return  labels.getString(key);
			
	 }
     
     protected String getNextId(String type){
            PreparedStatement ps=null;
            String id=null;
            try{
                
        
                ps=conn.prepareStatement(SQLConfig.getQuery("GETNEXT_ID"));
                ps.setString(1,type);
                ResultSet rs=ps.executeQuery();
                
                while(rs.next())
                    id=rs.getString("id");
                
                ps=conn.prepareStatement(SQLConfig.getQuery("UPDATENEXT_ID"));
                ps.setString(1,type);
                ps.execute();
        
            }
            catch(SQLException sqlex){
                sqlex.printStackTrace();
            }
            
            
            return id;
        }
	 
	
}
